﻿@{
    TempData["subMenu-check"] = new string[] { "User", "ManagePointTasks" };
    ViewData["Title"] = new string[] { "任务领取记录" };
    var taskRecordStatus = ViewData.Get<List<SelectListItem>>("taskRecordStatus", null);
    var tasks = ViewData.Get<List<SelectListItem>>("tasks", null);
    var taskId = ViewData.Get("taskId", 0);
}
<div class="row tn-page-heading tn-mb-10">
    <div class="col-xs-12">
        <h3><a href="@SiteUrls.Instance().ManagePointTasks()">积分任务</a> / 任务领取记录</h3>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-body">
        <div class="form-inline tn-tool-column">
            <div class="form-group">
                状态&nbsp;&nbsp;@Html.DropDownList("taskRecordStatus", taskRecordStatus, "全部", new { @class = "form-control searchPara" })
            </div>
            <div class="form-group">
                任务&nbsp;&nbsp;@Html.DropDownList("taskId", tasks, "全部", new { @class = "form-control searchPara" })
            </div>
            <div class="form-group">
                @Html.UserSelector("userId", null, mode: UserOrOrgSelectorMode.User, selectionNum: 50, innerText: "选择用户", validation: true, sourceUrl: SiteUrls.Instance().GetAllOguUser())
            </div>
            <div class="form-group pull-right">
                <button class="btn btn-primary" id="tasksearch" type="button">搜索</button>
            </div>
        </div>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-body" id="_ListTasktoUsers">
    </div>
</div>
<script>
    require(['jquery', 'tnlayer', 'userSelector','page'], function ($, tnlayer) {
        $(function () {
            $(".tn-choice-add").removeClass("tn-choice-add");
            if (@taskId > 0)
            {
                $("#taskId").val("@taskId");
            }
            getTasktoUser();
        });
        $(document).on("click", "#tasksearch", function () {
            getTasktoUser();
        }).on("change", ".searchPara", function () {
            getTasktoUser();
        }).on("click", ".deleterecord", function () {
            //删除记录
            var tasktoUserId = $(this).data("tasktouserid");
            layer.confirm("确定删除么？", {
                btn: ['确认', '取消'],//按钮
                scrollbar: false
            }, function () {
                var url = '@CachedUrlHelper.Action("DeleteTasktoUser", "ControlPanel")';
                $.post(url, { tasktoUserId: tasktoUserId }, function (data) {
                    if (data.MessageType == 1) {
                        getTasktoUser($("#pageIndex").val());
                        layer.msg(data.MessageContent, { icon: 1 });
                    }
                    else {
                        layer.msg(data.MessageContent, { icon: 2 });
                    }
                });
            });
        }).on("click", ".approvedtask", function () {
            layer.closeAll();
            //点击人工审核任务弹出任务框
            var tasktoUserId = $(this).data("tasktouserid");
            var taskName = $("#taskinfo").data("taskname");
            var url = "@CachedUrlHelper.Action("_PointTaskApprove", "ControlPanel")?t=" + (new Date).getTime();
            //页面层
            $.get(url, { recordId: tasktoUserId }, function (data) {
                layer.open({
                    type: 1,
                    title: taskName,
                    //skin: 'layui-layer-rim', //加上边框
                    area: ["400px", "400px"], //宽高
                    content: data,
                    scrollbar: true,
                    success:function(){
                        var sUserAgent = window.navigator.userAgent;
                        if (sUserAgent.toLowerCase().indexOf("trident") > -1 && sUserAgent.indexOf("rv") > -1) {
                            $(".layui-layer-content").height($(".layui-layer-content").height() - 30);
                        }
                    }

                });
            });
        }).on("click", "#taskover", function () {
            //人工审核通过
            var url = '@CachedUrlHelper.Action("PointTaskApprove", "ControlPanel")';
            $.post(url, { recordId: $(this).data("recordid") }, function (data) {
                if (data.MessageType == 1) {
                    layer.closeAll();
                    layer.msg(data.MessageContent, { icon: 1, time: 1000 });
                    getTasktoUser($("#pageIndex").val());
                }
                else {
                    layer.msg(data.MessageContent, { icon: 2 });
                }
            });
        }).on("click", "#feedback", function () {
            if($("#feedbackcontent").val()=="")
            {
                layer.msg("请输入反馈意见！", { icon: 2});
                return false;
            }
            //人工审核不通过，反馈意见
            var url = '@CachedUrlHelper.Action("PointTaskApprove", "ControlPanel")';
            $.post(url, { recordId: $(this).data("recordid"), feedback: $("#feedbackcontent").val() }, function (data) {
                if (data.MessageType == 1) {
                    layer.closeAll();
                    layer.msg(data.MessageContent, { icon: 1, time: 1000 });
                    getTasktoUser($("#pageIndex").val());
                }
                else {
                    layer.msg(data.MessageContent, { icon: 2 });
                }
            });
        });
        //获取勋章授予记录列表
        function getTasktoUser(pageIndex) {
            var url = '@CachedUrlHelper.Action("_ListTasktoUsers", "ControlPanel")?t=' + (new Date).getTime();
            var para = $(".searchPara").serializeArray();
            var userIds = [];
            var $userInput = $("input[name='userId']");
            if ($userInput.length > 0)
            {
                $userInput.each(function () {
                    userIds.push($(this).val());
                });
                para.push({ "name": "userId", "value": userIds.join(",") });
            }
            if (pageIndex > 0)
            {
                para.push({ "name": "pageIndex", "value": pageIndex })
            }
            $.get(url, para, function (data) {
                $("#_ListTasktoUsers").html(data);
            })
        }
    })
</script>
